package com.yunao.web.controller;/*
package com.yunao.server.web.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.yunao.server.service.IsearchService;
import com.yunao.server.utils.KeywordUtils;
import com.yunao.server.web.exception.ResourceNotFoundException;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yunao.common.core.bean.Article;
import com.yunao.common.core.bean.Articles;
import com.yunao.common.core.bean.Clusters;
import com.yunao.common.core.bean.Cubes;
import com.yunao.common.core.bean.Groups;
import com.yunao.common.core.bean.Wordclouds;
import com.yunao.common.core.bean.Wordrelations;
import com.yunao.common.utils.RequestParamUtils;

@RestController
@RequestMapping("v1/search")
public class SearchController {

	@Autowired
	IsearchService service;

	@RequestMapping
	public ResponseEntity<Articles> query(HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		Articles articles = service.query(params);
		return ResponseEntity.ok(articles);
	}

	@RequestMapping("reprints")
	public ResponseEntity<Articles> reprintQuery(@RequestParam(required = true) String text,
			HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		String keywords = KeywordUtils.extract(text);
		params.put("keywords", keywords);
		Articles articles = service.query(params);
		return ResponseEntity.ok(articles);
	}

	@RequestMapping(path = "{id}")
	public ResponseEntity<Article> queryById(@PathVariable long id, HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		params.put("id", String.valueOf(id));
		Articles articles = service.query(params);
		if (articles.getSize() > 0)
			return ResponseEntity.ok(articles.getData().get(0));
		throw new ResourceNotFoundException("Article", id);
	}

	@RequestMapping("group")
	public ResponseEntity<Groups> group(@RequestParam(required = true) String group, 
			HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		params.put("group", group);
		Groups groups = service.group(params);
		return ResponseEntity.ok(groups);
	}

	@RequestMapping("cube")
	public ResponseEntity<Cubes> cube(@RequestParam(required = true) String group, 
			@RequestParam(required = true) String group2, 
			HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		params.put("group", group);
		params.put("group2", group2);
		Cubes cubes = service.cube(params);
		return ResponseEntity.ok(cubes);
	}

	@RequestMapping("hotreprints")
	public ResponseEntity<Articles> distinct(@RequestParam(required = true) String keywords, HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		params.put("keywords", keywords);
		if (!(params.containsKey("between") 
				|| params.containsKey("greaterequal") 
				|| params.containsKey("greaterthan"))) {
			params.put("greaterequal", String.valueOf(DateTime.now().millisOfDay().withMinimumValue().getMillis()));
		}
		Articles articles = service.distinct(params);
		return ResponseEntity.ok(articles);
	}

	@RequestMapping("wordcloud")
	public ResponseEntity<Wordclouds> wordcloud(HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		Wordclouds wordclouds = service.wordcloud(params);
		return ResponseEntity.ok(wordclouds);
	}

	@RequestMapping("wordrelation")
	public ResponseEntity<Wordrelations> wordrelation(HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		Wordrelations wordrelations = service.wordrelation(params);
		return ResponseEntity.ok(wordrelations);
	}
	
	@RequestMapping("cluster")
	public ResponseEntity<Clusters> cluster(HttpServletRequest request) {
		Map<String, String> params = RequestParamUtils.parseParams(request);
		Clusters clusters = service.cluster(params);
		return ResponseEntity.ok(clusters);
	}


}
*/
